﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.Customization;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;
using DTO;
using BUS;

namespace GUI
{
    public partial class LapBaoCaoNam_GUI : DevExpress.XtraEditors.XtraUserControl
    {
        public LapBaoCaoNam_GUI()
        {
            InitializeComponent();
        }

        List<DoanhThuThang_DTO> listThang = DoanhThuThang_BUS.GetDoanhThuThangList();
        List<DoanhThuNam_DTO> listNam = DoanhThuNam_BUS.GetDoanhThuNamList();
        BindingList<ChiTietDoanhThuThang_DTO> listChiTiet = new BindingList<ChiTietDoanhThuThang_DTO>();

        string CreateMaDoanhThuThang()
        {
            string Kq = "DTT0";
            char[] c = "DTT0".ToCharArray();
            if (listThang.Count == 0)
            {
                Kq = "DTT01";
            }
            else
            {
                string Ma = DoanhThuThang_BUS.MaDoanhThuThangMax();
                Ma = Ma.TrimStart(c);
                Kq += Convert.ToString(Convert.ToInt32(Ma) + 1);
            }
            return Kq;
        }
        string CreateMaDoanhThuNam()
        {
            string Kq = "DTN0";
            char[] c = "DTN0".ToCharArray();
            if (listNam.Count == 0)
            {
                Kq = "DTN01";
            }
            else
            {
                string Ma = DoanhThuNam_BUS.MaxMaDoanhThuMan();
                Ma = Ma.TrimStart(c);
                Kq += Convert.ToString(Convert.ToInt32(Ma) + 1);
            }
            return Kq;
        }
        string CreateMaChiTietDoanhThu()
        {
            string Kq = "CTDT0";
            char[] c = "CTDT0".ToCharArray();
            BindingList<ChiTietDoanhThuThang_DTO> list = ChiTietDoanhThuThang_BUS.GetChiTietList();
            if (list.Count == 0)
            {
                Kq = "CTDT01";
            }
            else
            {
                string Ma = ChiTietDoanhThuThang_BUS.MaChiTietMax();
                Ma = Ma.TrimStart(c);
                Kq += Convert.ToString(Convert.ToInt32(Ma) + 1);
            }
            return Kq;
        }

        private void btnBaoCao_Click(object sender, EventArgs e)
        {
            if (DoanhThuNam_BUS.KiemTra(int.Parse(txtNam2.Text)) == true)
            {
                DoanhThuNam_DTO Nam = DoanhThuNam_BUS.GetDoanhThuNamDetails(int.Parse(txtNam2.Text));
                List<DoanhThuThang_DTO> list = DoanhThuThang_BUS.GetDoanhThuThangTheoNamList(Nam.MaDoanhNam);
                gridC_BaoCaoDoanhThu.DataSource = list;
            }
            else
            {
                MessageBox.Show("Bạn Chưa Lập Báo Cáo Tháng", "..:: Thông Báo ::..");
            }
        }

        private void btnXuatEx_Click(object sender, EventArgs e)
        {
            GridView view = gridC_BaoCaoDoanhThu.MainView as GridView;
            if (view != null)
            {
                view.ExportToPdf("Báo Cáo Doanh Thu Năm.pdf");
                Process pdfExport = new Process();
                pdfExport.StartInfo.FileName = "AcroRd32.exe";
                pdfExport.StartInfo.Arguments = "Báo Cáo Doanh Thu Năm.pdf";
                pdfExport.Start();
            }
        }
    }
}
